package com.jic.veteran.controller;

import com.google.common.collect.Maps;
import com.jic.veteran.common.api.CommonResult;
import com.jic.veteran.dto.AlumniAddAccommodationParam;
import com.jic.veteran.dto.AlumniAddNewsParam;
import com.jic.veteran.dto.AlumniAddTeacherParam;
import com.jic.veteran.dto.AlumniSchoolInfoParam;
import com.jic.veteran.model.AlumniSchoolAccommodation;
import com.jic.veteran.model.AlumniSchoolNews;
import com.jic.veteran.model.AlumniSchoolTeachers;
import com.jic.veteran.service.AlumniSchoolService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;


/**
 * 文章管理controller
 * Created by mars on 2021/11/23.
 */
@RestController
@Api(tags = "AlumniSchoolController",description = "学校信息")
@RequestMapping("/school")
public class AlumniSchoolController {

    @Autowired
    private AlumniSchoolService alumniSchoolService;

    @ApiOperation("修改学校信息")
    @RequestMapping(value = "/schoolinfo", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult editSchoolInfo(@RequestBody AlumniSchoolInfoParam alumniSchoolInfoParam) {

         int count = alumniSchoolService.schoolInfo(alumniSchoolInfoParam);
        return CommonResult.success(null);
     }

    @ApiOperation("老师分页")
    @RequestMapping(value = "/pageteachers", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<Map<String, List<AlumniSchoolTeachers>>> getPageTeachers(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                                                 @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                                                 @RequestParam(value = "teacherName", defaultValue = "") String teacherName,
                                                                                 @RequestParam(value = "status", defaultValue = "3") Integer status
    ) {

        List<AlumniSchoolTeachers> alumniSchoolTeachers = alumniSchoolService.getPageTeachers(pageSize,pageNum,teacherName,status);
        Map<String, List<AlumniSchoolTeachers>> map = Maps.newHashMapWithExpectedSize(20);
        map.put("list", alumniSchoolTeachers);
        return CommonResult.success(map);
    }

    @ApiOperation("更改教师展示状态")
    @RequestMapping(value = "/upteacherstatus", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult upTeacherStatus(@RequestParam(value = "id", required = true) Integer id,
                                        @RequestParam(value = "status", required = true) Integer status
    ) {

        int count = alumniSchoolService.upTeacherStatus(id,status);
        return CommonResult.success(null);
    }

    @ApiOperation("新增教师信息")
    @RequestMapping(value = "/addteacher", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult addTeacher(@RequestBody AlumniAddTeacherParam alumniAddTeacherParam) {

        int count = alumniSchoolService.addTeacher(alumniAddTeacherParam);
        return CommonResult.success(null);
    }


    @ApiOperation("修改教师信息")
    @RequestMapping(value = "/aditteacher/{id}", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult aditTeacher(@PathVariable Integer id, @RequestBody AlumniAddTeacherParam alumniAddTeacherParam) {

        int count = alumniSchoolService.aditTeacher(id,alumniAddTeacherParam);

        if (count > 0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }

    @ApiOperation("删除教师信息")
    @RequestMapping(value = "/deleteteacher/{id}", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult deleteTeacher(@PathVariable Integer id) {

        int count = alumniSchoolService.deleteTeacher(id);

        if (count > 0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }

    @ApiOperation("新闻分页")
    @RequestMapping(value = "/pagenews", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<Map<String, List<AlumniSchoolNews>>> getPageNews(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                                         @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                                         @RequestParam(value = "newsName", defaultValue = "") String newsName,
                                                                         @RequestParam(value = "status", defaultValue = "3") Integer status
    ) {

        List<AlumniSchoolNews> alumniSchoolNews = alumniSchoolService.getPageNews(pageSize,pageNum,newsName,status);
        Map<String, List<AlumniSchoolNews>> map = Maps.newHashMapWithExpectedSize(20);
        map.put("list", alumniSchoolNews);
        return CommonResult.success(map);
    }


    @ApiOperation("更改news展示状态")
    @RequestMapping(value = "/upnewsstatus", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult upNewsStatus(@RequestParam(value = "id", required = true) Integer id,
                                        @RequestParam(value = "status", required = true) Integer status
    ) {

        int count = alumniSchoolService.upNewsStatus(id,status);
        return CommonResult.success(null);
    }

    @ApiOperation("新增news")
    @RequestMapping(value = "/addnews", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult addNews(@RequestBody AlumniAddNewsParam alumniAddNewsParam) {

        int count = alumniSchoolService.addNews(alumniAddNewsParam);
        return CommonResult.success(null);
    }


    @ApiOperation("修改news信息")
    @RequestMapping(value = "/aditnews/{id}", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult aditNews(@PathVariable Integer id, @RequestBody AlumniAddNewsParam alumniAddNewsParam) {

        int count = alumniSchoolService.aditNews(id,alumniAddNewsParam);

        if (count > 0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }

    @ApiOperation("删除news")
    @RequestMapping(value = "/deletenews/{id}", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult deleteNews(@PathVariable Integer id) {

        int count = alumniSchoolService.deleteNews(id);

        if (count > 0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }





    @ApiOperation("周边食宿分页")
    @RequestMapping(value = "/pageaccommodation", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<Map<String, List<AlumniSchoolAccommodation>>> getPageAlumniSchoolAccommodation(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                                                                       @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                                                                       @RequestParam(value = "accommodationName", defaultValue = "") String alumniSchoolAccommodationName,
                                                                                                       @RequestParam(value = "type", defaultValue = "3") Integer type
    ) {

        List<AlumniSchoolAccommodation> alumniSchoolAccommodation = alumniSchoolService.getPageAccommodation(pageSize,pageNum,alumniSchoolAccommodationName,type);
        Map<String, List<AlumniSchoolAccommodation>> map = Maps.newHashMapWithExpectedSize(20);
        map.put("list", alumniSchoolAccommodation);
        return CommonResult.success(map);
    }



    @ApiOperation("新增周边食宿")
    @RequestMapping(value = "/addaccommodation", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult addAccommodation(@RequestBody AlumniAddAccommodationParam alumniAddAccommodationParam) {

        int count = alumniSchoolService.addAccommodation(alumniAddAccommodationParam);
        return CommonResult.success(null);
    }


    @ApiOperation("修改周边食宿信息")
    @RequestMapping(value = "/aditaccommodation/{id}", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult aditAccommodation(@PathVariable Integer id, @RequestBody AlumniAddAccommodationParam alumniAddAccommodationParam) {

        int count = alumniSchoolService.aditAccommodation(id,alumniAddAccommodationParam);

        if (count > 0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }

    @ApiOperation("删除周边食宿")
    @RequestMapping(value = "/deleteaccommodation/{id}", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult deleteAccommodation(@PathVariable Integer id) {

        int count = alumniSchoolService.deleteAccommodation(id);

        if (count > 0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }

}
